<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
        <title>增加WIFI信息</title>
        
        <link rel="stylesheet" type="text/css" href="../css/cm-default.css"  />
        <link rel="stylesheet" type="text/css" href="../ligerUI/skins/Aqua/css/ligerui-all.css" />
        <link rel="stylesheet" type="text/css" href="../ligerUI/skins/ligerui-icons.css" />
        <script src="../js/jquery-min.js" type="text/javascript"></script>
        <script src="../ligerUI/js/ligerui.min.js" type="text/javascript"></script>
        <script src="../js/common.js" type="text/javascript"></script>
        <script src="../js/json2.js" type="text/javascript"></script>
        <script type="text/javascript" src="../js/md5.js"></script>
        <script src="../js/validate/jquery.validate.js" type="text/javascript"></script>
        <script src="../js/validate/jquery.metadata.js" type="text/javascript"></script>
        <script src="../js/validate/messages_zh.js" type="text/javascript"></script>
        <script type="text/javascript">
             var opt,c_code,shop_no; 
            $(function(){
                var query = getQueryString(window.location.toString());
                opt = query.o;
                if (opt) {
                    c_code = query.code;
                    shop_no = query.shop_no;
                    if (opt === 'm') {
                        var param = {wifi_no:c_code};
                        var data = JSON.stringify(reqObj('q','wifi.select.wifi_basic_info.query',JSON.stringify(param)));
                        ajaxSubmit("/cmwifi/rbac/cm.do?m=c", data, function(data) {
                            bindVal(data['data']);
                        }, null, false);
                        
                        ajaxSubmit("/cmwifi/rbac/cmUser.do?method=getUserInfo", null, function(data) {
                            $('#WriteUserCodeS').val(data['uid']);
                            $("#WriteDateS").val(data['date']);
                        }, null, false);
                    }else{
                    	 $('#newShop_NameS').val(paramRender(null,'shop_list',shop_no));
                    	 $('#shop_no').val(shop_no);
                    	 ajaxSubmit("/cmwifi/rbac/cmUser.do?method=getUserInfo", null, function(data) {
                             $('#createUserS').val(data['uname']);
                             $('#createUserCodeS').val(data['uid']);
                             $("#createDateS").val(data['date']);
                         }, null, false);
                    }
                }
                
                //是否有效
                $("#newWifi_UseableTxtS").ligerComboBox({
                    autocomplete: true,
                    valueField:'value',
                    textField:'name',
                    data:getData('rbac.status'),
                    onSelected:function(v,t) {
                        $("#wifi_useable").val(v);
                }
               });
                
                $("#newShop_NameS").ligerComboBox({
                    autocomplete: true,
                    valueField:'value',
                    textField:'name',
                    data:getData('shop_list'),
                    onSelected:function(v,t) {
                        $("#shop_no").val(v);
                }
               });
                
                $("#newWifi_encrypS").ligerComboBox({
                    autocomplete: true,
                    valueField:'value',
                    textField:'name',
                    data:getData('encryp_list'),
                    onSelected:function(v,t) {
                        $("#wifi_encryp").val(v);
                }
               });
                
                $("#pageloading").hide();
                });
            var getshop_list= new function () {
                return getData('shop_list');
            }
           //密码状态获取
           var getStatus = new function () {
               return getData('rbac.status');
           }
           //保存处理中值check处理
           function validate() {
               var valid = true;
               $('*[id$="S"],*[id$="S_txt"]').each(function(index, element) {
                   if (!$(this).rules()) return;
                   if (!$(element).valid()) {
                       valid = false;
                       return;
                   }
               });
               if (!valid) return false;
               return true;
           }

           //重置处理
           function resetArea() {
               toReset('#a_center input:not(.readonly),select,textarea');
           }
           // 查询时数据值绑定  应该可以抽象为公共的功能
           function bindVal(data) {
               if (data.Rows && data.Rows.length === 1) {
                   data = data.Rows[0];
                   $('#wifi_no').val(data.wifi_no);
                   $('#newWifi_SsidS').val(data.wifi_ssid);
                   $('#newWifi_PwdS').val(data.wifi_pwd);
                   $('#newWifi_UseableTxtS').val(paramRender(null,'rbac.status',data.wifi_useable));
                   $('#wifi_useable').val(data.wifi_useable);
                   $('#newShop_NameS').val(paramRender(null,'shop_list',data.shop_no));
                   $('#shop_no').val(data.shop_no);
                   $('#newWifi_encrypS').val(paramRender(null,'encryp_list',data.wifi_encryp));
                   $('#wifi_encryp').val(data.wifi_encryp);
                   $('#newWifi_LongitudeS').val(data.wifi_longitude);                 
                   $('#newWifi_LatitudeS').val(data.wifi_latitude);
                   $('#createUserS').val(paramRender(null,'user',data.createuser));
                   $('#createUserCodeS').val(data.createuser);
                   $('#createDateS').val(data.createdate);
               }
           }
           // 保存业务处理
           function toAdd() {
              if (!validate())
                  return;
               var param = {
            		   wifi_no:$('#wifi_no').val(),
            		   wifi_ssid:$('#newWifi_SsidS').val(),
                       wifi_pwd:$('#newWifi_PwdS').val(),
                       shop_name:$('#newShop_NameS').val(),
                       shop_no:$('#shop_no').val(),
                       wifi_longitude:$('#newWifi_LongitudeS').val(),                 
                       wifi_latitude:$('#newWifi_LatitudeS').val(),
                       wifi_useable:$('#wifi_useable').val(),
                       wifi_encryp:$('#wifi_encryp').val(),
                       
               };
               var en = 'wifi.add.wifi_basic_info.insert', optType = 'a';
               if (opt === 'm') {
                   
                   //修改人
                   param.writeuser=$('#WriteUserCodeS').val();
                   //修改日期
                   param.writedate=$('#WriteDateS').val();
                   // 进行修改数据库处理
                   en = 'wifi.update.wifi_basic_info.update';
                   // 操作类型为 update
                   optType = 'u';
               } else {
                   // 新增时 数据处理
                   param.createuser = $("#createUserCodeS").val();
                   param.createdate = $("#createDateS").val();
               }
               var data = JSON.stringify(reqObj(optType,en,JSON.stringify(param)));
               ajaxSubmit("/cmwifi/rbac/cm.do?m=c", data, function(data) {
                    $.ligerDialog.success('保存成功', '操作完成',closeDialog);
               });
           }
           //重新加载页面 ，在保存时调用
            function closeDialog() {
                if (opt === 'm') {
                     parent.modifyDialog.hide();
                }else{
                     parent.addDialog.hide();
                }
                parent.toQuery();//调父窗口某个方法
               }
       </script>
       <style type="text/css">
           .center-height{height: 100%;}
       </style>
   </head>
   <body style="padding:0;">
       <div id="pageloading"></div>
       <div id="layout_main">
           <div position="center" id="a_center" title="WIFI基本信息" style="overflow:hide;">
               <form name="basic-form" method="post" id="basic_form" class="liger-form" data-validate="{}">
                <div class="line-div">
                <div class="label-div"><label>商户名称</label></div>
                <div class="in-div"><input type="text" id="newShop_NameS" ltype="text" class="readonly diff" readonly ="readonly" /></div>
                <input type="hidden" id="shop_no" />
                <div class="label-div"><label>WIFI编号</label></div>
                <div class="in-div"><input type="text" ltype="text" class="readonly diff" id="wifi_no" readonly ="readonly" value="系统自动生成"/></div>
               </div>
                <div class="line-div">
                <div class="label-div"><label>WIFI名称</label></div>
                <div class="in-div"><input type="text" ltype="text" class="required s-text txt-def" id="newWifi_SsidS" /></div>
                <div class="label-div"><label>WIFI密码</label></div>
                <div class="in-div"><input type="password"  ltype="text" class="required s-text txt-def" id="newWifi_PwdS" /></div>
               </div>
               <div class="line-div">
                <div class="label-div"><label>WIFI加密方式</label></div>
                <div class="in-div"><input type="text"  ltype="combobox" class="required s-text txt-def" id="newWifi_encrypS" /></div>
                <input type="hidden" id="wifi_encryp" />
                <div class="label-div"><label>是否有效</label></div>
                <div class="in-div"><input type="text" id="newWifi_UseableTxtS" ltype="combobox" class="required" /></div>
                <input type="hidden" id="wifi_useable" />
               </div>
               <div class="line-div">
               <div class="label-div"><label>WIFI经度</label></div>
                <div class="in-div"><input type="text" class="required s-text txt-def" id="newWifi_LongitudeS" /></div>
                <div class="label-div"><label>WIFI纬度</label></div>
                <div class="in-div"><input type="text" class="required s-text txt-def" id="newWifi_LatitudeS" /></div>
                </div>
               <input type="hidden" id="createUserCodeS" />
               <input type="hidden" id="createUserS" />
               <input type="hidden" id="createDateS" />
               <input type="hidden" id="WriteUserCodeS" />
               <input type="hidden" id="WriteDateS" />
            </form>
              <div class="line-div" style="margin-top:50px;padding-left:40%;">
                <input type="button" value="保存" onclick="toAdd();" />
                <input type="button" value="清空" onclick="toReset('#a_center input,select')" />
              </div>
       </div>
   </body>
</html>